namespace DotNetNuke.Security.Permissions.Controls
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Web.UI.WebControls;

    public class CheckBoxColumn : TemplateColumn
    {
        private static List<WeakReference> __ENCList = new List<WeakReference>();
        private CheckBoxTemplate mEditItem;
        private CheckBoxTemplate mViewItem;

        public event EditCheckedChangedEventHandler EditCheckedChanged;

        public event ViewCheckedChangedEventHandler ViewCheckedChanged;

        public CheckBoxColumn()
        {
            List<WeakReference> refObjectHelperL0 = __ENCList;
            lock (refObjectHelperL0)
            {
                __ENCList.Add(new WeakReference(this));
            }
            this.mViewItem = new CheckBoxTemplate(true);
            base.ItemTemplate = this.mViewItem;
            this.mEditItem = new CheckBoxTemplate(true);
            this.mViewItem.BoxCheckedChanged += new CheckBoxTemplate.BoxCheckedChangedEventHandler(this.OnEditCheckedChanged);
            base.EditItemTemplate = this.mEditItem;
            base.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
        }

        public CheckBoxColumn(bool ImmediatePostback, [Optional, DefaultParameterValue("true")] string trueValue)
        {
            List<WeakReference> refObjectHelperL0 = __ENCList;
            lock (refObjectHelperL0)
            {
                __ENCList.Add(new WeakReference(this));
            }
            this.mViewItem = new CheckBoxTemplate(ImmediatePostback, trueValue);
            this.mViewItem.BoxCheckedChanged += new CheckBoxTemplate.BoxCheckedChangedEventHandler(this.OnViewCheckedChanged);
            base.ItemTemplate = this.mViewItem;
            this.mEditItem = new CheckBoxTemplate(!ImmediatePostback, trueValue);
            this.mEditItem.BoxCheckedChanged += new CheckBoxTemplate.BoxCheckedChangedEventHandler(this.OnEditCheckedChanged);
            base.EditItemTemplate = this.mEditItem;
            base.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            this.AutoPostBack = ImmediatePostback;
        }

        public void OnEditCheckedChanged(int gridIndex, bool @checked)
        {
            EditCheckedChangedEventHandler refObjectHelperS0 = this.EditCheckedChanged;
            if (refObjectHelperS0 != null)
            {
                refObjectHelperS0(gridIndex, @checked);
            }
        }

        public void OnViewCheckedChanged(int gridIndex, bool @checked)
        {
            ViewCheckedChangedEventHandler refObjectHelperS0 = this.ViewCheckedChanged;
            if (refObjectHelperS0 != null)
            {
                refObjectHelperS0(gridIndex, @checked);
            }
        }

        public bool AutoPostBack
        {
            get
            {
                return this.mViewItem.AutoPostBack;
            }
            set
            {
                this.mViewItem.AutoPostBack = value;
                this.mEditItem.AutoPostBack = value;
            }
        }

        public string DataField
        {
            get
            {
                return this.mViewItem.DataField;
            }
            set
            {
                this.mViewItem.DataField = value;
                this.mEditItem.DataField = value;
            }
        }

        public delegate void EditCheckedChangedEventHandler(int gridIndex, bool @checked);

        public delegate void ViewCheckedChangedEventHandler(int gridIndex, bool @checked);
    }
}

